package com.keyinong.qudan.dapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.keyinong.qudan.R;
import com.keyinong.qudan.entity.GoodsInfoBean;

public class CaidanAdapter extends BaseAdapter{
	Context context;
	ArrayList<GoodsInfoBean> caidanList;
	
	public CaidanAdapter(Context context, ArrayList<GoodsInfoBean> caidanList) {
		super();
		this.context = context;
		this.caidanList = caidanList;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return caidanList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return caidanList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		final ViewHandle handle;
		if(view==null){
			handle=new ViewHandle();
			view=LayoutInflater.from(context).inflate(R.layout.item_caidan, null);
			handle.tv_name=(TextView)view.findViewById(R.id.tv_name);
			handle.tv_amount=(TextView)view.findViewById(R.id.tv_amount);
			handle.tv_price=(TextView)view.findViewById(R.id.tv_price);
			view.setTag(handle);
		}else {
			handle = (ViewHandle) view.getTag();	
		}
		if (caidanList.get(position).getSname().equals("null")||caidanList.get(position).getSname().equals("")) {
			handle.tv_name.setText(caidanList.get(position).getName());
		}else {
			handle.tv_name.setText(caidanList.get(position).getName()+"("+caidanList.get(position).getSname()+")");
		}
		handle.tv_amount.setText("*"+caidanList.get(position).getAmount());
		handle.tv_price.setText("￥"+Double.parseDouble(caidanList.get(position).getPrice())*Integer.parseInt(caidanList.get(position).getAmount()));
		return view;
	}
	class ViewHandle {
		/**菜品*/
		TextView tv_name;
		/**数量*/
		TextView tv_amount;
		/**单价*/
		TextView tv_price;
	}
}
